package com.daxidi.cn.controller;

import com.daxidi.cn.entity.Log;
import com.daxidi.cn.mapper.LogMapper;
import com.daxidi.cn.service.ILogService;
import com.daxidi.cn.utils.ReturnResult;
import com.daxidi.cn.utils.ReturnResultUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.log4j.Log4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;
@Log4j
@Api(tags = "日志模块")
@RestController
@RequestMapping("/api/v1/union/log")
public class LogController {
    @Autowired
    private ILogService logService;
    @Autowired
    private LogMapper logMapper;

    @ApiOperation(value = "日志记录查询")
    @GetMapping("/logs")
    public Map selectLog(@RequestParam(defaultValue = "1") Integer page, @RequestParam(defaultValue = "20") Integer limit) {
        Map map = logService.selectAll(page, limit);
        return map;
    }

    @ApiOperation(value = "搜索日志记录接口")
    @GetMapping("/search")
    public Map search(@RequestParam(defaultValue = "1") Integer page, @RequestParam(defaultValue = "20") Integer limit,String name,String beginTime,String endTime) {
        Map map = logService.search(page, limit, name,beginTime,endTime);
        return map;
    }

    @ApiOperation(value = "导出日志记录")
    @GetMapping("/importLog")
    public ReturnResult importLog(@RequestParam(defaultValue = "1") Integer page, @RequestParam(defaultValue = "20") Integer limit,String name,String beginTime,String endTime) {
        try {
            page = 1;
            limit = 999999;
            Map search = logService.search(page, limit, name, beginTime, endTime);
//            Map map = logService.search(page, limit, name,beginTime,endTime);
            return ReturnResultUtils.returnSuccess(search);
        } catch (Exception e) {
            log.error("下载失败" + e);
            return ReturnResultUtils.returnFailMsg(198, "下载失败");
        }
    }
}
